package com.example.chenduoyun.safe.activity;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.GestureDetector;
import android.view.MotionEvent;

/**
 * @author by created chen cloudy 2018/10/12 17:03
 **/

public abstract class BaseSetupActivity extends Activity {
    private GestureDetector gestureDetector;
    private final int judgeNumber=100;
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        gestureDetector = new GestureDetector
                (this, new GestureDetector.SimpleOnGestureListener() {
                    @Override
                    public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
                                           float velocityY) {
                        if (e1.getRawX() - e2.getRawX() > judgeNumber) {
                            showNextPage();

                        }
                        if (e2.getRawX() - e1.getRawX() > judgeNumber) {
                            showPrePage();
                        }
                        return super.onFling(e1, e2, velocityX, velocityY);
                    }
                });


    }

    public abstract void showNextPage();
    public abstract void showPrePage();
    @Override
    public boolean onTouchEvent(MotionEvent event) {
        gestureDetector.onTouchEvent(event);
        return super.onTouchEvent(event);
    }
}
